<%@ page language="java" import="java.util.*,com.model.DoorDetail" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="css/common.css">
<link rel="stylesheet" href="css/punishment.css">
<script src="js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<style type="text/css">
table {
	border-collapse: collapse;
	border-spacing: 0;
}

td, th {
	padding: 0;
}

.pure-table {
	border-collapse: collapse;
	border-spacing: 0;
	empty-cells: show;
	border: 1px solid #cbcbcb;
}

.pure-table caption {
	color: #000;
	font: italic 85%/1 arial, sans-serif;
	padding: 1em 0;
	text-align: center;
}

.pure-table td, .pure-table th {
	border-left: 1px solid #cbcbcb;
	border-width: 0 0 0 1px;
	font-size: inherit;
	margin: 0;
	overflow: visible;
	padding: .5em 1em;
}

.pure-table thead {
	background-color: #e0e0e0;
	color: #000;
	text-align: left;
	vertical-align: bottom;
}

.pure-table td {
	background-color: transparent;
}

.pure-table-odd {
	background-color: #f2f2f2;
}
</style>
</head>
<body>
	<div class="container">
		<div class="content">
			<div class="header clearfix">
				<div class="top fl">当前位置>详细预约订单</div>
			</div>
			<div class="main">
				<!--基础信息-->
				<div class="BasicInformation">
					<div class="title">详细预约订单</div>
				</div>
				<form action="EmployeeServlet" method="post">
						<input type="text" name="oid" value="" style="margin:5px" placeholder="请输入订单编号">
						<input type="hidden" name="action" value="queryDetail">
						<input type="submit"  value="搜索" style="height:30px;margin:5px">
						<span>订单的编号：</span>
						<span id="span_oid"><%= request.getParameter("oid")==null?"":request.getParameter("oid")%></span> 
						<a href="EmployeeServlet?action=toaddView&oid=<%=request.getParameter("oid") %>" style="margin-left:110px" id="a_add">
							添加出售种类
						</a>
					</form>
				<!--在此处添加表格-->
				<div class="pure-table">
				
					<table>
							<thead>
								<tr>
									<th style="width:100px">种类名称</th>
									<th style="width:100px">单价</th>
									<th style="width:150px">重量</th>
									<th style="width:150px">小计</th>
									<th style="width:120px">操作</th>
								</tr>
							</thead>
							<tbody>
								<c:forEach items="${requestScope.details}" var ="detail">
									<tr>
										<input type="hidden" id="oid" value="${detail.oid}">
										<input type="hidden" id="pid" value="${detail.pid}">
										<input type="hidden" id="oldtprice" value="${detail.tprice}">
										<td>${detail.pname}</td>
										<td id="pprice">${detail.pprice}</td>
										
										<td>
											<input type="text" name="weight" id="weight" class="weight" value="${detail.weight}">
										</td>
										<td id="tprice" >${detail.tprice}</td>
										<td>
											<a href="EmployeeServlet?action=del&oid=${detail.oid}&pid=${detail.pid}&tprice=${detail.tprice}">
												<button >删除</button>
											</a>
											<a>
												<button onclick="save(this)">保存</button>
											</a>
										</td>
									</tr>
								</c:forEach>
							</tbody>
						</table>
				</div>
				
			</div>
		</div>
	</div>
	<script src="js/jquery-1.9.1.min.js"></script>
	<script>
		//控制表格的单双行的背景颜色
	   	$(".pure-table tr:even").addClass("pure-table-odd");
	
        $('select').attr('value','0');
        $.ajax({
            url: "http://101.201.154.205:9090/survey/getSurveyByStuId",
            data: {
                stuId:1,
                t: Math.random()
            },
            type: 'get',
            dataType: 'jsonp',
            'jsonp': 'callback'
            }).then(function (res) {
            $('select option').each(function(index,arg){
                if($(this).val() == res.entrance){
                    $(this).attr('selected','selected');
                }
            });
            $('select').attr('value',res.entrance);
            $('#expect_salary').attr('value',res.expect_salary);
            $('#situation').text(res.situation);
            $('#city').attr('value',res.city);
            $('#work_pro').attr('value',res.work_pro);
            $('#remarks').attr('value',res.remarks);
            $('#unit_pro').attr('value',res.unit_pro);
            $('#province').attr('value',res.province);


        },function (err) {
            console.log(err);
        });
        $('.l').click(function () {
            $('.oInp').removeAttr('disabled');
        });

        $('.r').click(function () {
            $('.oInp').attr('disabled','disabled');

            $.ajax({
                url: "http://101.201.154.205:9090/survey/surveyUpdateDo",
                data: {
                    stu_id:"1",
                    expect_salary:$('#expect_salary').val(),
                    entrance:$('select').val(),
                    remarks:$('#remarks').val(),
                    province:$('#province').val(),
                    city:$('#city').val(),
                    situation:$('#situation').val(),
                    work_pro:$('#work_pro').val(),
                    unit_pro:$('#unit_pro').val(),
                    t: Math.random()
                },
                type: 'get',
                dataType: 'jsonp',
                'jsonp': 'callback'
            }).then(function (res) {
                console.log(res);

            },function (err) {
                console.log(err);
            });


        });
        
        //修改重量
		$(".weight").each(function(){
			$(this).blur(function(){
				var pprice =$(this).parent().prev().html();
				var weight =$(this).val();
				if(weight<0){
					alert("请正确输入重量");
					$(this).val(0);
					$(this).parent().next().html("0");
				}else{
					$(this).parent().next().html(new Number(pprice)*new Number(weight));
					 
				}
				
			})
		})
		//保存
		function save(e){
			var weight=new Number($("#weight").val());
			var tprice=new Number($("#tprice").html());
			var oldtprice=new Number($("#oldtprice").val());
			var oid=$("#oid").val();
			var pid=$("#pid").val();
			alert("原先oldtprice:"+oldtprice);
			alert("现在tprice:"+tprice);
			alert("原先oid:"+oid);
			alert("现在pid:"+pid);
			$.ajax({
				//请求地址
	            url : "EmployeeServlet?action=save",
	            //请求方式
	            type : "post",
	            //数据，json字符串
	            data : {
	            	"weight":weight,
	            	"tprice":tprice,
	            	"oid":oid,
	            	"pid":pid,
	            	"action":"save",
	            	"oldtprice":oldtprice
	            },
	            dataType:"text",
	            //请求成功
	            success : function(result) {
	                if(result==1){
	                	alert("修改成功");
	                }
	            },
	            //请求失败，包含具体的错误信息
	            error : function(e){
	               alert("修改失败");
	            }
	        });
			
        }
	
       //控制a标签是否可用
		$("#a_add").click(function() {
			
			if ($("#span_oid").html() == "") {
				alert("请先输入订单的编号");
				$("#a_add").attr("href", "#");
			}
		})
	</script>

</body>
</html>
